package com.squirrel.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询、更新、删除语句中共有sql
 *
 * @author wangyan
 */
public abstract class AbstractCreateSql implements ICreateSql {

    private List<Map<String, Object>> filterWhereList;
    private List<Map<String, Object>> filterAndList;
    private List<Map<String, Object>> filterOrList;
    private Map<String, Object> fieldLoopMap;


    public AbstractCreateSql() {
        this.filterWhereList = new ArrayList<>();
        this.filterAndList = new ArrayList<>();
        this.filterOrList = new ArrayList<>();
        this.fieldLoopMap = new HashMap<>();
    }

    public List<Map<String, Object>> getWhereFilterList() {
        return this.filterWhereList;
    }

    public List<Map<String, Object>> getAndFilterList() {
        return this.filterAndList;
    }

    public List<Map<String, Object>> getOrFilterList() {
        return this.filterOrList;
    }

    public void setWhere(String field, String condition, Long value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterWhereList.add(fieldMap);
    }

    public void setWhere(String field, String condition, String value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterWhereList.add(fieldMap);
    }

    public void setWhere(String field, String condition, LocalDateTime value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterWhereList.add(fieldMap);
    }

    public void setWhere(String field, String condition, List<Object> valueList) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", valueList);
        filterWhereList.add(fieldMap);
    }

    public void setWhere(String field, String condition, Object value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterWhereList.add(fieldMap);
    }

    public final void setAnd(String field, String condition, String value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterAndList.add(fieldMap);
    }

    public final void setAnd(String field, String condition, long value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterAndList.add(fieldMap);
    }

    public final void setAnd(String field, String condition, LocalDate value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value.toString());
        filterAndList.add(fieldMap);
    }

    public void setAnd(String field, String condition, LocalDateTime value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterAndList.add(fieldMap);
    }

    public void setAnd(String field, String condition, List<Object> valueList) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", valueList);
        filterAndList.add(fieldMap);
    }

    public void setAnd(String field, String condition, Object valueList) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", valueList);
        filterAndList.add(fieldMap);
    }

    public void setForeach(String field, String condition, String value) {
        filterAndList.clear();
        fieldLoopMap.clear();
        fieldLoopMap.put("field", field);
        fieldLoopMap.put("condition", condition);
        fieldLoopMap.put("value", value);
        filterAndList.add(fieldLoopMap);
    }

    public final void setOr(String field, String condition, String value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value);
        filterOrList.add(fieldMap);
    }

    public final void setOr(String field, String condition, LocalDate value) {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("field", field);
        fieldMap.put("condition", condition);
        fieldMap.put("value", value.toString());
        filterOrList.add(fieldMap);
    }


}
